import React, { useRef } from "react";
import {ProTable, ActionType} from '@ant-design/pro-components';
import { evaluationProjectV1AdminControllerAll } from "@/services/auto/evaluationProjectAdmin";
import { evaluationProjectType, EvaluationProjectType } from "common/utils/data";

export default function EvaluationProject(){
  const actionRef = useRef<ActionType>();

  return <ProTable<API.EvaluationProjectAllResult>
    actionRef={actionRef}
    rowKey="uuid"
    search={false}
    pagination={false}
    toolBarRender={() => []}
    request={() => {
      return evaluationProjectV1AdminControllerAll().then((res) => {
        return {
          success: true,
          data: res,
        };
      });
    }}
    columns={[
      {
        align: 'center',
        title: '名称',
        dataIndex: 'name',
        hideInSearch: true,
      },
      {
        align: 'center',
        title: 'CODE',
        dataIndex: 'code',
        hideInSearch: true,
      },
      {
        align: 'center',
        title: '排序',
        dataIndex: 'sort',
        hideInSearch: true,
        valueType: 'digit',
      },
      {
        align: 'center',
        title: '描述',
        dataIndex: 'desc',
        valueType: 'textarea',
        ellipsis: true,
        hideInSearch: true,
      },
      {
        align: 'center',
        title: '类型',
        dataIndex: 'type',
        hideInSearch: true,
        renderText: (val) => evaluationProjectType[val as EvaluationProjectType]
      },
      {
        align: 'center',
        title: '规则',
        dataIndex: 'rule',
        ellipsis: true,
        width: 400,
        hideInSearch: true,
        render: (_, record) => <div className="whitespace-pre-wrap">
          {JSON.stringify(record.rule, null, 2)}
        </div>,
      },
    ]}
  />
}
